{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-11-11T08:07:56.094453Z",
     "start_time": "2025-11-11T08:07:56.022216Z"
    }
   },
   "source": [
    "# 张量的存储逻辑\n",
    "\n",
    "import torch\n",
    "\n",
    "points = torch.tensor([[4, 1],[5, 3],[2, 1]])\n",
    "points.storage()"
   ],
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_12340\\2544948205.py:6: UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly.  To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage()\n",
      "  points.storage()\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       " 4\n",
       " 1\n",
       " 5\n",
       " 3\n",
       " 2\n",
       " 1\n",
       "[torch.storage.TypedStorage(dtype=torch.int64, device=cpu) of size 6]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 2
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-11T08:09:34.341282Z",
     "start_time": "2025-11-11T08:09:34.338470Z"
    }
   },
   "cell_type": "code",
   "source": [
    "points_storage = points.storage()\n",
    "points_storage[2]\n",
    "\n",
    "print(points)\n"
   ],
   "id": "920791ceece3de2c",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[4, 1],\n",
      "        [5, 3],\n",
      "        [2, 1]])\n"
     ]
    }
   ],
   "execution_count": 5
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-11T08:09:45.922029Z",
     "start_time": "2025-11-11T08:09:45.919892Z"
    }
   },
   "cell_type": "code",
   "source": "points_storage[2] = 9",
   "id": "21acb237c33d52c1",
   "outputs": [],
   "execution_count": 6
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-11T08:09:58.531253Z",
     "start_time": "2025-11-11T08:09:58.528414Z"
    }
   },
   "cell_type": "code",
   "source": "print(points)",
   "id": "c257aa9e84c0caab",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[4, 1],\n",
      "        [9, 3],\n",
      "        [2, 1]])\n"
     ]
    }
   ],
   "execution_count": 7
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-11T08:11:58.446714Z",
     "start_time": "2025-11-11T08:11:58.442749Z"
    }
   },
   "cell_type": "code",
   "source": [
    "\n",
    "a3 =  torch.ones(3, 3)\n",
    "print(a3)\n",
    "a3.storage()\n",
    "\n"
   ],
   "id": "60c5db7156fd41d5",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[1., 1., 1.],\n",
      "        [1., 1., 1.],\n",
      "        [1., 1., 1.]])\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       " 1.0\n",
       " 1.0\n",
       " 1.0\n",
       " 1.0\n",
       " 1.0\n",
       " 1.0\n",
       " 1.0\n",
       " 1.0\n",
       " 1.0\n",
       "[torch.storage.TypedStorage(dtype=torch.float32, device=cpu) of size 9]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 10
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-11T08:12:10.556572Z",
     "start_time": "2025-11-11T08:12:10.553860Z"
    }
   },
   "cell_type": "code",
   "source": [
    "a3.zero_()\n",
    "print(a3)"
   ],
   "id": "703bf717e068c8fa",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[0., 0., 0.],\n",
      "        [0., 0., 0.],\n",
      "        [0., 0., 0.]])\n"
     ]
    }
   ],
   "execution_count": 11
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-11T08:12:20.206939Z",
     "start_time": "2025-11-11T08:12:20.203603Z"
    }
   },
   "cell_type": "code",
   "source": "a3.storage()",
   "id": "70508b502fec673f",
   "outputs": [
    {
     "data": {
      "text/plain": [
       " 0.0\n",
       " 0.0\n",
       " 0.0\n",
       " 0.0\n",
       " 0.0\n",
       " 0.0\n",
       " 0.0\n",
       " 0.0\n",
       " 0.0\n",
       "[torch.storage.TypedStorage(dtype=torch.float32, device=cpu) of size 9]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 13
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-11T08:17:02.305283Z",
     "start_time": "2025-11-11T08:17:02.302022Z"
    }
   },
   "cell_type": "code",
   "source": [
    "points = torch.tensor([[4,1,3,2], [5,3,7,8], [2,1,9,5], [3,8,4,5]])\n",
    "sencod_points = points[1:, 1:]\n",
    "\n",
    "print(points)\n",
    "print(\"============\")\n",
    "print(sencod_points)"
   ],
   "id": "e2b0e1177d842878",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[4, 1, 3, 2],\n",
      "        [5, 3, 7, 8],\n",
      "        [2, 1, 9, 5],\n",
      "        [3, 8, 4, 5]])\n",
      "============\n",
      "tensor([[3, 7, 8],\n",
      "        [1, 9, 5],\n",
      "        [8, 4, 5]])\n"
     ]
    }
   ],
   "execution_count": 18
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-11T08:18:24.935650Z",
     "start_time": "2025-11-11T08:18:24.932459Z"
    }
   },
   "cell_type": "code",
   "source": "points.storage_offset()",
   "id": "5caf39972303838c",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 20
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-11T08:18:42.376999Z",
     "start_time": "2025-11-11T08:18:42.373728Z"
    }
   },
   "cell_type": "code",
   "source": "sencod_points.storage_offset()",
   "id": "ac9d260e64311377",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 21
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-11T08:20:08.307789Z",
     "start_time": "2025-11-11T08:20:08.304579Z"
    }
   },
   "cell_type": "code",
   "source": "points.stride()",
   "id": "f045a1392026b6bb",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(4, 1)"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 22
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-11T08:20:45.008049Z",
     "start_time": "2025-11-11T08:20:45.004746Z"
    }
   },
   "cell_type": "code",
   "source": "sencod_points.stride()",
   "id": "9a684dbe85bf2aa",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(4, 1)"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 23
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-11T08:23:21.370393Z",
     "start_time": "2025-11-11T08:23:21.358740Z"
    }
   },
   "cell_type": "code",
   "source": "points.is_contiguous()",
   "id": "59c58eb2971e30fc",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 24
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-11T08:23:36.373411Z",
     "start_time": "2025-11-11T08:23:36.370103Z"
    }
   },
   "cell_type": "code",
   "source": "sencod_points.is_contiguous()",
   "id": "5a96ce51a5375c07",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 25
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-11T08:24:28.745728Z",
     "start_time": "2025-11-11T08:24:28.742224Z"
    }
   },
   "cell_type": "code",
   "source": [
    "s2 = sencod_points.clone()\n",
    "s2.is_contiguous()\n"
   ],
   "id": "ac00ec270eba2206",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 27
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
